﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MiniTwitter.Extensions;

namespace MiniTwitter.Net.Twitter {
	//this class added by yuki.
	class SearchResult : PropertyChangedBase, ITwitterItem {
		#region ITwitterItem メンバ

		private DateTime _createdAt;
		public DateTime CreatedAt {
			get {
				return _createdAt;
			}
			set {
				if (_createdAt != value) {
					_createdAt = value;
					OnPropertyChanged("CreatedAt");
					this.UpdateRelativeTime();
				}
			}
		}

		private string _relativeTime;
		public string RelativeTime {
			get {
				return _relativeTime;
			}
			set {
				if (_relativeTime != value) {
					_relativeTime = value;
					OnPropertyChanged("RelativeTime");
				}
			}
		}

		private long _id;
		public long ID {
			get {
				return _id;
			}
			set {
				if (_id != value) {
					_id = value;
					OnPropertyChanged("ID");
				}
			}
		}

		private string _idString;
		public string IdSTring {
			get {
				return _idString;
			}
			set {
				if (_idString == value) return;

				_idString = value;
				OnPropertyChanged("RelativeTime");

				string[] strs = _idString.Split(new char[] { ':' });
				try {
					long id = long.Parse(strs[strs.Length - 1]);
					this.ID = id;
				} catch {
				}
			}
		}

		private string _text;
		public string Text {
			get {
				return _text;
			}
			set {
				if (_text != value) {
					_text = value;
					OnPropertyChanged("Text");
				}
			}
		}

		private bool _isAuthor;
		public bool IsAuthor {
			get {
				return _isAuthor;
			}
			set {
				if (_isAuthor != value) {
					_isAuthor = value;
					OnPropertyChanged("IsAuthor");
				}
			}
		}

		private bool _isNewest;
		public bool IsNewest {
			get {
				return _isNewest;
			}
			set {
				if (IsNewest != value) {
					_isNewest = value;
					OnPropertyChanged("IsNewest");
				}
			}
		}

		public bool IsMessage {
			get { return false;  }
		}

		private User _sender;
		public User Sender {
			get {
				return _sender;
			}
			set {
				if (_sender != value) {
					_sender = value;
					OnPropertyChanged("Sender");
				}
			}
		}

		private User _recipient;
		public User Recipient {
			get {
				return _recipient;
			}
			set {
				if (_recipient != value) {
					_recipient = value;
					OnPropertyChanged("Recipient");
				}
			}
		}

		#endregion

		#region IEquatable<ITwitterItem> メンバ

		public bool Equals(ITwitterItem other) {
			if (other == null || !(other is SearchResult)) return false;

			return this.IdSTring == ((SearchResult)other).IdSTring;
		}

		#endregion
	}
}
